﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace day7_case3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Calculator calc = new Calculator();
            while (true)
            {
                double a, b, res = 0;
                char operation;
                Console.WriteLine("欢迎使用简单计算器！");
                Console.WriteLine("请输入第一个数字");
                a = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("请输入操作符");
                operation = Convert.ToChar(Console.ReadLine());
                Console.WriteLine("请输入第二个数字");
                b = Convert.ToDouble(Console.ReadLine());

                switch (operation)
                {
                    case '+':
                        res = calc.Add(a, b);
                        break;
                    case '-':
                        res = calc.Subtract(a, b);
                        break;
                    case '*':
                        res = calc.Multiply(a, b);
                        break;
                    case '/':
                        res = calc.Divide(a, b);
                        break;
                    default:
                        Console.WriteLine("请输入+-*/合法运算符");
                        continue;
                }
                Console.WriteLine("{0}{1}{2}的结果是{3}", a, operation, b, res);
                Console.WriteLine("等待用户按Enter键继续");
                Console.ReadLine(); // 等待用户按Enter键继续
            }
        }
    }

    public class Calculator
    {
        public double Add(double a, double b)
        {
            return a + b;
        }

        public double Subtract(double a, double b)
        {
            return a - b;
        }

        public double Multiply(double a, double b)
        {
            return a * b;
        }

        public double Divide(double a, double b)
        {
            if (b == 0)
            {
                throw new DivideByZeroException("除数不能为0");
            }
            return a / b;
        }
    }
}
